<?php

// +----------------------------------------------------------------------
// | 小说系统 [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------

namespace app\common\model;

/**
* 设置模型  用户表彰表
*/
class UserHonour extends Base
{
    protected $name = "UserHonour";
    protected $auto = array('update_time','status'=>1);
	protected $append=[
		'honour_time_text'
	];
	public function getHonourTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['honour_time']) ? $data['honour_time'] : '');
        return is_numeric($value) ? date("Y-m-d", $value) : $value;
    }

    public function edit($data, $uid)
    {
        sort($data);
        $list=$this->where('uid', $uid)->update(['status'=>0]);
        for ($i=0;$i<count($data);$i++) {
            if ($data[$i]['honour_title']!=''&&$data[$i]['honour_time']!='') {
                $mp=[
                    'honour_title'=>$data[$i]['honour_title'],
                    'honour_content'=>$data[$i]['honour_content'],
                    'honour_time'=>strtotime($data[$i]['honour_time'].'00:00:00'),
					'uid'=>$uid,
                    'status'=>'1'
                ];
                if ($data[$i]['honour_id']!='') {
                    $mp['update_time']=time();
                    $this->where('id', $data[$i]['honour_id'])->update($mp);
                } else {
                    $mp['create_time']=time();
                    $this->create($mp);
                }
            }
        }
    }
}
